- Senior Software Engineer
- CDI co-spec lead, Java EE 8 EG
- Red Hat, Inc.
- @antoine_sd
- www.next-presso.com
- github.com/antoinesd
| Slides available at rafabene.github.io/deltaspike-cdi-toolbox/ |
| OCP (Open Closed Principle) in CDI |
| To integrate 3rd party libraries, frameworks or legacy components |
| To change existing configuration or behavior |
| To extend CDI and Java EE |
| Thanks to them, Java EE can evolve between major releases |
| Implement javax.enterprise.inject.spi.Extension |
| Register the Extension |
| Observe SPI events at boot time related to the bean manager lifecycle |
Service provider of the service javax.enterprise.inject.spi.Extension declared in META-INF/services |
| Just put the fully qualified name of your extension class in this file |
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.Extension;
public class CdiExtension implements Extension {
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) {
}
//...
void afterDeploymentValidation(@Observes AfterDeploymentValidation adv) {
}
} @Inject @Property("key1")
private String property1;
@Inject @Property("key2")
private String property2;| It can be achieved by @Produces but it could lead to: Unsatisfied dependencies for type String with qualifiers @Property… |
@Produces
@Property("key1")
public String propriedade1Producer()
{
return propertiesFile.getProperty("key1");
}| One of the most powerful feature of the CDI specification |
| Not really popularized, partly due to: |
| CDI is a specification. It doesn’t provide business features |
| but it includes a powerful hook to add these business features |
| The "Poortable extensions" feature is this hook |
| Thanks to it, CDI can be easily enhanced with new high level features |
| A collection of ready to use extensions to help you in your projects |
| A toolbox to help you develop new CDI portable extensions |
| A great way to learn how to develop your own extension by browsing the source code |
| The most obvious entry point to CDI eco-system |
TODO Move content to here
TODO Move content to here
TODO Move content to here